package com.aldobucchi.utils
{


	import flash.utils.Dictionary;
	


	public class FactoryCache
	{
	
		private var dict:Dictionary;
	
		private var func:Function;
	
		public function FactoryCache( func:Function, weakKeys:Boolean = false )
		{
			
			this.func = func;
			
			dict = new Dictionary( weakKeys );
			
		}
	
		
		public function getValue( key:* ):*
		{
		
			if ( dict[ key ] === undefined )
			{
				dict[ key ] = func.apply( null, [ key ] );
			}
			
			return dict[ key ];
		
		}
		
		
		public function clear( ):void
		{
		
			for ( var key:* in dict )
			{
				
				delete dict[ key ];
			
			}
		
		}
		

	}
	
}